home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- *
- * Create an Offscreen GWorld, Randomize and Sort it
- *
- * GWorld.h - C Source
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * Notice the inheritance of WindowObj
- *
- *************************************************************************************/
- #ifndef __GWORLDOBJ__
- #define __GWORLDOBJ__
-
- #include "WindowObj.h"
- #include <QDOffscreen.h>
- #include "main.h"
- #include <Threads.h>
- #include <GestaltEqu.h>
- #include "WindowObj.Link"
-
- #define ABOUTDIALOG 128
- #define ABOUTDIALOGPICT 3
- #define ABOUTPICTURENAMEID 145
-
- #define PICTURESMENU 132
- #define USEROPTIONSMENU 131
- #define UO_ERASE 1
- #define UO_QUALUDES 2
- #define UO_CONTINUOUS5Sec 3
- #define UO_CONTINUOUS0Sec 4
- #define UO_SAVEWINDPOS 5
- #define UO_SORT_0 6
- #define UO_SORT_1 7
- #define UO_BLANK 8
- #define UO_SHOWTTYDELAY 9
- #define UO_DECREASETTY 10
- #define UO_INCREASETTY 11
-
- #define mSortAlgorithm 133
- #define iShellSort 1
- #define iHeapSort 2
- #define iQuickSort 3
- #define iRandomSort 5
-
-
- // This is just lame... but MPW C++ doesn't support the inherited operator
- #define inherited WindowObj
-
-
- class GWorldObj : public inherited {
- private:
- int savedCount;
- CGrafPtr savedPort;
- GDHandle savedGDH;
- PicHandle sortPict;
- Rect worldPictRect; // Where in the GWorld the pict lies
- Rect windPictRect; // Where in the Window the Pict lies
- GWorldPtr sortGWorld;
- long **sortList;
- long *sortListPtr;
- Size sortListSize; // Usually called N in most text books
- #define N sortListSize /* That sets it OK */
- short pictWidth,
- pictHeight,
- pictRowBytes;
- long threadResult;
- Byte *offscreenPtr;
- Size offset;
- long yieldTime;
- GrafPtr savePort;
- short percentComplete; // Used during randomization
-
- Boolean randomizing; // True during the randomization process
- Boolean aboutBox; // True when this window is the about box!
- Str255 windowTitle; // Held during drag!!
- Boolean needToUpdateWindowTitle;// Set True when window Title Δ during drag
- long finishedTime; // Used for continuous operation
- public:
- // User Options that apply to all windows
- static short gSortSize; // 0 == Actual Picts, 1 == Cool, 2 == Totally art deco
- static Boolean gEraseWindow; // User defined... do we erase the window before CopyBits?
- static short gYieldDelay; // How long to wait before switching
- static short gNumPictures; // The number of pictures in resource fork
- static MenuHandle gPicturesMenu; // The place to hold the names of the picts
- static short gWindOffSet; // How far to set off each window...
- static Boolean gHasThreads; // Are threads present on this Mac??
- static Boolean gQualudesUpdate; // This Engages CopyBits to Copy to Whole window.. it's cool
- static Boolean gContinuous; // As soon as sorting is done, rescramble the whole mess!!
- static short gContinuousTime; // How long to wait.. 0Sec or 5Sec?
- static Boolean gSaveWindowPositions; // When windows are moved... save their positions
- static short gNextBkgndWindowNum; // The next window to get Background events
- static short gSortAlgorithm; // Which menu item is selected
-
- short sortAlgorithm; // Which sort for this window
-
- #ifdef __powerc
- ModalFilterUPP AboutBoxFilterUPP; // A UniversalProcPtr
- #endif
-
- private:
- // The following is random number stuff
- long randomSeed;
- Rect copyBitsRect;
-
- public:
- Boolean doneSorting; // Features based on during/post sort time
- ThreadID threadInfo; // This was made public so it can be
- // set to Ø when the sort has completed.
- Str255 pictureName; // Picture Name that the user selected
- Boolean yieldOnlyToMe; // True while the user holds down the mouse button
-
-
-
- public:
- // Window stuff
- virtual void InitObj( void);
- virtual Boolean NewWindowObj( void);
- virtual Boolean BeginNewThread( void);
- virtual void MouseClickObj( EventRecord *event);
- virtual void BackGroundObj( void); // Same as Idle obj, only background idle
- virtual void IdleObj( void);
- virtual void GrowWindowObj( EventRecord *event);
- virtual Boolean CloseWindowObj( void);
- virtual void DrawObj( void);
- virtual void DrawGrowIconObj( void);
- virtual void MenuObj( short menu, short item, EventRecord *event);
- virtual void AdjustMenusObj( void);
- virtual Boolean AboutObj( void);
- virtual void UpdateObj( void);
- virtual void DragWindowObj( EventRecord *event);
- virtual void SetTitle( ConstStr255Param title);
- Boolean PrepareGWorld( void);
- void UseGWorld( void);
- void UnuseGWorld( void);
-
- // Sort kind-a stuff
- void ShellSort( void);
- void HeapSort( void);
- void BuildHeap( void);
- void Heapify( long size, long index);
- void QuickSort( void);
- void ChooseMedian( long a, long b, long c);
- void QuickSortEngine( long left, long right, char *);
- void ExchangeSortItem( long one, long theOther);
- void SetSortItem( long index, long data);
- OSErr YieldIfTime( char *mmuMode);
-
- // Scrmbling stuff
- void ScramblePict( void);
-
- // Random Number stuff
- long RandomPixel( long max); // returns 0 ≤ random < max
- };
-
-
- #endif
-
-